package com.thoughtworks.collection;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.util.*;

public class Add {

       public int getSumOfEvens(int leftBorder, int rightBorder) {
        //求leftBorder 和rightBorder之间的偶数和
        int sumOfEvens=0;
        if (leftBorder<rightBorder){
            for (int i=leftBorder;i<rightBorder;i++){
                if (i%2==0){
                    sumOfEvens+=1;
                }
            }
        }else{
            for (int i=rightBorder;i<leftBorder;i++){
                if (i%2==0){
                    sumOfEvens+=1;
                }
            }
        }
        return sumOfEvens;
        // throw new NotImplementedException();
    }

    public int getSumOfOdds(int leftBorder, int rightBorder) {
        //求leftBorder 和rightBorder之间的奇数和
        int sumOfOdds=0;
        if (leftBorder<rightBorder){
            for (int i=leftBorder;i<rightBorder;i++){
                if (i%2!=0){
                    sumOfOdds+=1;
                }
            }
        }else{
            for (int i=rightBorder;i<leftBorder;i++){
                if (i%2!=0){
                    sumOfOdds+=1;
                }
            }
        }
        return sumOfOdds;

//       throw new NotImplementedException();
    }

    public int getSumTripleAndAddTwo(List<Integer> arrayList) {
        //求数组中每个元素的3倍加2的和
//        int sumTripleAndAddTwo=0;
//        for (int i=0;i<arrayList.size();i++){
//            sumTripleAndAddTwo += arrayList.get(i) *3+2;
//        }
//        return sumTripleAndAddTwo;
       throw new NotImplementedException();
    }

    public List<Integer> getTripleOfOddAndAddTwo(List<Integer> arrayList) {
        //求数组中奇数元素的3倍加2，偶数元素不变的数组
        Integer[] arrayNew = new Integer[]{};
        List<Integer> arrayListNew = Arrays.asList(arrayNew);
        for (int i=0;i<arrayList.size();i++){
            if (arrayList.get(i) %2!=0){
                arrayListNew.add(i);
            }else {
                arrayListNew.add(arrayList.get(i));
            }
        }
        return arrayListNew;

 //       throw new NotImplementedException();
    }

    public int getSumOfProcessedOdds(List<Integer> arrayList) {
        //求数组中奇数元素的3倍加5的和
        int sumOfProcessedOdds = 0;
        for (int i = 0; i < arrayList.size(); i++) {
            if (arrayList.get(i) % 2 != 0) {
                sumOfProcessedOdds += arrayList.get(i) * 3 + 5;
            }
        }
        return sumOfProcessedOdds;
       // throw new NotImplementedException();
    }
    public double getMedianOfEven(List<Integer> arrayList) {
        //求数组中所有偶数组成的数组的中位数
        double medianOfEven=0;
        Integer[] arrayNew = new Integer[]{};
        List<Integer> arrayListNew = Arrays.asList(arrayNew);
        for (int i=0;i<arrayList.size();i++){
            if (arrayList.get(i)%2==0){
                arrayListNew.add(i);
            }
        }
        ArrayList arrayListSort= (ArrayList) sortByEvenAndOdd( arrayListNew);
        int len = arrayListSort.size();
        if (len%2!=0){
            medianOfEven= (double) arrayListSort.get((len-1)/2);
        }else {
            medianOfEven= (double) arrayListSort.get((len / 2 + (len / 2 - 1)) / 2);

        }
        return medianOfEven;
  //     throw new NotImplementedException();
    }

    public double getAverageOfEven(List<Integer> arrayList) {
        //求数组中所有偶数的平均数
        double averageOfEven=0;
        double sumOfEven=0;
        for (int i=0;i<arrayList.size();i++){
            if (arrayList.get(i)%2==0){
                sumOfEven+=arrayList.get(i);
            }
        }
        averageOfEven=sumOfEven/arrayList.size();
        return averageOfEven;

  //      throw new NotImplementedException();

    }

    public boolean isIncludedInEvenIndex(List<Integer> arrayList, Integer specialElment) {
        // 求数组中所有偶数组成的数组是否包含某特定的数specialElment
        Integer[] arrayEven = new Integer[]{};
        List<Integer> arrayListEven = Arrays.asList(arrayEven);
        for (int i=0;i<arrayList.size();i++){
            if (arrayList.get(i)%2==0){
                arrayListEven.add(i);
            }
        }
        return arrayListEven.contains(specialElment);
  //      throw new NotImplementedException();
    }

    public List<Integer> getUnrepeatedFromEvenIndex(List<Integer> arrayList) {
        //找出数组中的所有偶数，从中剔除重复数据并返回
        Integer[] arrayEven = new Integer[]{};
        List<Integer> arrayListEven = Arrays.asList(arrayEven);
        for (int i=0;i<arrayList.size();i++){
            if (arrayList.get(i)%2==0){
                arrayListEven.add(i);
            }
        }
        return deDuplication(arrayListEven);
       // throw new NotImplementedException();
    }

    private List<Integer> deDuplication(List<Integer> arrayListEven) {
        Set<Integer> collectionWithoutDuplicates = new HashSet<>(arrayListEven);
        return new ArrayList<>(collectionWithoutDuplicates);
    }

    public List<Integer> sortByEvenAndOdd(List<Integer> arrayList) {
        //排序数组 结果使数组偶数在递增在前，奇数递减在后


       throw new NotImplementedException();
    }

    public List<Integer> getProcessedList(List<Integer> arrayList) {
         throw new NotImplementedException();
        //return null;
    }
}
